package film.servlets;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import film.examples.HtmlParserEx;
import film.utils.ContentSites;
import film.webObjs.FilmPage;

/**
 * Servlet implementation class FilmServlet
 */
public class FilmServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public FilmServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		response.setContentType("text/html");
		PrintWriter out = response.getWriter();
		 
		ContentSites cn=new ContentSites();
		try {

			cn.analyzeMainContent(HtmlParserEx.getContent2("http://direkizle.net/"));
			cn.lookAtFilmPages();			
			
			for (FilmPage film : cn.getFilmPages()) {
//				System.out.println("title:"+film.getName());
				out.println("--------------------------------------------------------------------------------------------------");
				out.println("title:<hr>"+film.getName());
				out.println(film.getAciklama());
				
//				out.println("<h3>links:</h3><hr>");
					
				for(int i=0;i<film.getVideoLinks().size();i++){
					System.out.println(film.getVideoLinks().get(i));
//					out.println(film.getVideoLinks().get(i));
				}
					
				

			}
			
			
		} catch (IOException e) {

			e.printStackTrace();
		}
			
		
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
